package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 注意：Mapper中开发，注解方式和xml方式只能选其一。
 */

@Mapper
public interface EmpMapper {


    @Delete("delete from emp where dept_id = #{deptId};")
    void deleteByDeptId(Integer deptId);

    @Select("select count(*) from emp;")
    long count();

    @Select("select * from emp limit #{startIndex},#{pageSize};")
    List<Emp> pageQuery(@Param("startIndex") int startIndex, @Param("pageSize") Integer pageSize);

    /*@Select("select * from emp") //注意：语句后面不要加分号，否则底层拦截拼接语句的时候会把分号拼接过去，使语法错误
    Page<Emp> list();*/

    Page<Emp> list(@Param("name") String name,
                   @Param("gender") Short gender,
                   @Param("begin") LocalDate begin,
                   @Param("end") LocalDate end);


    void deleteById(@Param("ids") List<Integer> ids);

    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "value (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("select * from emp where id=#{id} ;")
    Emp getById(Integer id);

    void update(Emp emp);

    @Select("select * from emp where username=#{username} and password = #{password} ;")
    Emp getByUsernameAndPassword(Emp emp);
}
